package com.ssy.lingxi.purchase.controller.tender;

import cn.hutool.core.bean.BeanUtil;
import com.ssy.lingxi.common.constant.Constants;
import com.ssy.lingxi.common.constant.manage.ShopTypeEnum;
import com.ssy.lingxi.common.constant.member.RoleTypeEnum;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.model.dto.MemberLrcCacheDTO;
import com.ssy.lingxi.common.model.dto.UserLoginCacheDTO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.component.redis.service.IRedisUtils;
import com.ssy.lingxi.purchase.api.dto.request.tender.*;
import com.ssy.lingxi.purchase.api.dto.response.tender.*;
import com.ssy.lingxi.purchase.api.enums.tender.*;
import com.ssy.lingxi.purchase.entity.tender.*;
import com.ssy.lingxi.purchase.service.tender.IInviteTenderService;
import com.ssy.lingxi.purchase.service.tender.ITemplateService;
import com.ssy.lingxi.search.api.model.request.SimpleIdListRequest;
import com.ssy.lingxi.workflow.api.model.vo.response.ComplexTaskDefVO;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author jw.chen
 * @version 2.0.0
 * @menu: 招投标-招标管理
 * 招标管理类
 * @date 2021/3/1
 */
@RestController
@RequestMapping("/purchase/inviteTender")
public class InviteTenderController extends BaseController {

    @Resource
    private IRedisUtils redisUtils;

    @Resource
    private IInviteTenderService inviteTenderService;

    @Resource
    private ITemplateService templateService;

    /**
     * 查询招标列表--企业直采首页
     * @param current  当前页码
     * @param pageSize 每页条数
     */
    @RequestMapping(value = "/getInviteTenderListByEnterpriseWeb", method = RequestMethod.GET)
    public Wrapper<PageData<InviteTenderEnterpriseWebResponse>> getInviteTenderListByEnterpriseWeb(
            @RequestParam("current") int current,
            @RequestParam("pageSize") int pageSize,
            @RequestParam(value = "startTime", required = false) Long startTime,
            @RequestParam(value = "endTime", required = false) Long endTime,
            @RequestParam(value = "category", required = false) Long category,
            @RequestParam(value = "provinceCode", required = false) String provinceCode,
            @RequestParam(value = "cityCode", required = false) String cityCode,
            @RequestParam(value = "overdue", required = false) Boolean overdue,
            @RequestParam(value = "orderType", required = false) Integer orderType,
            @RequestParam(value = "keyword", required = false) String keyword) {
        Long shopId = this.getHeadersShopId();
        Long loginMemberId = null;
        Integer memberRoleType = null;
        //判断是否已登录
        if (this.isLogin()) {
            UserLoginCacheDTO sysUser = this.getSysUser();
            loginMemberId = sysUser.getMemberId();
            memberRoleType = sysUser.getMemberRoleType();
        }
        //构建查询条件
        InviteTenderQueryRequest inviteTenderQueryRequest = new InviteTenderQueryRequest();
        inviteTenderQueryRequest.setInviteTenderType(InviteTenderTypeEnum.Open.getCode());
        inviteTenderQueryRequest.setShopId(shopId);
        inviteTenderQueryRequest.setCurrent(current);
        inviteTenderQueryRequest.setPageSize(pageSize);
        inviteTenderQueryRequest.setStartTime(startTime);
        inviteTenderQueryRequest.setEndTime(endTime);
        inviteTenderQueryRequest.setProjectName(keyword);
        inviteTenderQueryRequest.setCategoryId(category);
        inviteTenderQueryRequest.setProvinceCode(provinceCode);
        inviteTenderQueryRequest.setCityCode(cityCode);
        inviteTenderQueryRequest.setOverdue(overdue);
        inviteTenderQueryRequest.setOrderType(orderType);
        Page<InviteTender> result = inviteTenderService.getInviteTenderList(null, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        if (inviteTenderList.size() > 0) {
            Long finalLoginMemberId = loginMemberId;
            Integer finalMemberRoleType = memberRoleType;

            //招标会员积分
            List<String> keyList = inviteTenderList.stream().map(inviteTender -> {
                Long memberId = inviteTender.getMemberId();
                Long memberRoleId = inviteTender.getMemberRoleId();
                return Constants.MEMBER_LRC_PREFIX + Constants.MEMBER_LRC_SPLIT + memberId + Constants.MEMBER_LRC_SPLIT + memberRoleId;
            }).distinct().collect(Collectors.toList());
            HashMap<String, Integer> memberLrcMap = new HashMap<>();
            for (int i = 0; i < keyList.size(); i++) {
                memberLrcMap.put(keyList.get(i), i);
            }
            List<Object> memberLrcList = redisUtils.getBatch(keyList, Constants.REDIS_USER_INDEX);

            List<InviteTenderEnterpriseWebResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
                InviteTenderEnterpriseWebResponse inviteTenderEnterpriseWebResponse = BeanUtil.copyProperties(inviteTender, InviteTenderEnterpriseWebResponse.class);
                Long memberId = inviteTender.getMemberId();
                Long memberRoleId = inviteTender.getMemberRoleId();
                //招标会员积分
                String mapKey = Constants.MEMBER_LRC_PREFIX + Constants.MEMBER_LRC_SPLIT + memberId + Constants.MEMBER_LRC_SPLIT + memberRoleId;
                Integer index = memberLrcMap.get(mapKey);
                if (index != null) {
                    Object obj = memberLrcList.get(index);
                    if (obj != null) {
                        MemberLrcCacheDTO memberLrcCacheDTO = (MemberLrcCacheDTO) obj;
                        Integer creditPoint = memberLrcCacheDTO.getCreditPoint();
                        if (creditPoint != null && creditPoint > 0) {
                            inviteTenderEnterpriseWebResponse.setCreditScore(creditPoint);
                        }
                    }
                }

                //招标物料信息
                List<InviteTenderMateriel> materielList = inviteTender.getMaterielList();
                if (materielList != null && materielList.size() > 0) {
                    inviteTenderEnterpriseWebResponse.setCategoryName(materielList.stream().map(InviteTenderMateriel::getCategoryName).collect(Collectors.joining(",")));
                    inviteTenderEnterpriseWebResponse.setInviteTenderMaterielCount(materielList.size());
                }

                //计算报名剩余时间
                long nowTime = System.currentTimeMillis();
                long registerEndTime = inviteTenderEnterpriseWebResponse.getRegisterEndTime();
                if (nowTime < registerEndTime) {
                    long m = registerEndTime - nowTime;
                    long days = m / 1000 / (60 * 60 * 24);
                    inviteTenderEnterpriseWebResponse.setDays(days);
                    m = m - days * 1000 * (60 * 60 * 24);
                    long hours = m / 1000 / (60 * 60);
                    inviteTenderEnterpriseWebResponse.setHours(hours);
                    m = m - hours * 1000 * (60 * 60);
                    long minutes = m / 1000 / 60;
                    inviteTenderEnterpriseWebResponse.setMinutes(minutes);
                }

                //用户已登录
                if (finalLoginMemberId != null) {
                    //判断是否已经报名了
                    List<InviteTenderMember> memberList = inviteTender.getMemberList();
                    memberList.forEach(inviteTenderMember -> {
                        //投标会员
                        Long submitTenderMemberId = inviteTenderMember.getMemberId();
                        if (finalLoginMemberId.equals(submitTenderMemberId)) {
                            inviteTenderEnterpriseWebResponse.setIsRegister(true);
                        }
                    });
                    //判断能否可以报名
                    inviteTenderEnterpriseWebResponse.setCanRegister(RoleTypeEnum.SERVICE_PROVIDER.getCode().equals(finalMemberRoleType) && !inviteTender.getMemberId().equals(finalLoginMemberId));
                }

                return inviteTenderEnterpriseWebResponse;
            }).collect(Collectors.toList());
            return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
        } else {
            return Wrapper.success(new PageData<>(result.getTotalElements(), null));
        }
    }

    /**
     * 查询招标列表--采购门户首页
     * @param current      当前页码
     * @param pageSize     每页条数
     * @param memberId     采购商的会员id
     * @param memberRoleId 采购商的会员角色id
     */
    @RequestMapping(value = "/getInviteTenderListByDoorWeb", method = RequestMethod.GET)
    public Wrapper<PageData<InviteTenderDoorWebResponse>> getInviteTenderListByDoorWeb(
            @RequestParam("current") int current,
            @RequestParam("pageSize") int pageSize,
            @RequestParam("memberId") Long memberId,
            @RequestParam("memberRoleId") Long memberRoleId,
            @RequestParam(value = "startTime", required = false) Long startTime,
            @RequestParam(value = "endTime", required = false) Long endTime,
            @RequestParam(value = "category", required = false) Long category,
            @RequestParam(value = "provinceCode", required = false) String provinceCode,
            @RequestParam(value = "cityCode", required = false) String cityCode,
            @RequestParam(value = "overdue", required = false) Boolean overdue,
            @RequestParam(value = "orderType", required = false) Integer orderType,
            @RequestParam(value = "keyword", required = false) String keyword) {
        Long shopId = this.getHeadersShopId();
        Long loginMemberId = null;
        Integer memberRoleType = null;
        //判断是否已登录
        if (this.isLogin()) {
            UserLoginCacheDTO sysUser = this.getSysUser();
            loginMemberId = sysUser.getMemberId();
            memberRoleType = sysUser.getMemberRoleType();
        }

        UserLoginCacheDTO sysUser = new UserLoginCacheDTO();
        sysUser.setMemberId(memberId);
        sysUser.setMemberRoleId(memberRoleId);
        //构建查询条件
        InviteTenderQueryRequest inviteTenderQueryRequest = new InviteTenderQueryRequest();
        inviteTenderQueryRequest.setInviteTenderType(InviteTenderTypeEnum.Open.getCode());
        inviteTenderQueryRequest.setShopId(shopId);
        inviteTenderQueryRequest.setCurrent(current);
        inviteTenderQueryRequest.setPageSize(pageSize);
        inviteTenderQueryRequest.setStartTime(startTime);
        inviteTenderQueryRequest.setEndTime(endTime);
        inviteTenderQueryRequest.setProjectName(keyword);
        inviteTenderQueryRequest.setCategoryId(category);
        inviteTenderQueryRequest.setProvinceCode(provinceCode);
        inviteTenderQueryRequest.setCityCode(cityCode);
        inviteTenderQueryRequest.setOverdue(overdue);
        inviteTenderQueryRequest.setOrderType(orderType);
        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        if (inviteTenderList.size() > 0) {
            Long finalLoginMemberId = loginMemberId;
            Integer finalMemberRoleType = memberRoleType;
            List<InviteTenderDoorWebResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
                InviteTenderDoorWebResponse inviteTenderDoorWebResponse = BeanUtil.copyProperties(inviteTender, InviteTenderDoorWebResponse.class);
                List<InviteTenderMateriel> materielList = inviteTender.getMaterielList();
                if (materielList != null && materielList.size() > 0) {
                    inviteTenderDoorWebResponse.setCategoryName(materielList.stream().map(InviteTenderMateriel::getCategoryName).collect(Collectors.joining(",")));
                    inviteTenderDoorWebResponse.setInviteTenderMaterielCount(materielList.size());
                }

                //计算报名剩余时间
                long nowTime = System.currentTimeMillis();
                long registerEndTime = inviteTenderDoorWebResponse.getRegisterEndTime();
                if (nowTime < registerEndTime) {
                    long m = registerEndTime - nowTime;
                    long days = m / 1000 / (60 * 60 * 24);
                    inviteTenderDoorWebResponse.setDays(days);
                    m = m - days * 1000 * (60 * 60 * 24);
                    long hours = m / 1000 / (60 * 60);
                    inviteTenderDoorWebResponse.setHours(hours);
                    m = m - hours * 1000 * (60 * 60);
                    long minutes = m / 1000 / 60;
                    inviteTenderDoorWebResponse.setMinutes(minutes);
                }

                //判断是否登录
                if (finalLoginMemberId != null) {
                    //判断是否已经报名了
                    List<InviteTenderMember> memberList = inviteTender.getMemberList();
                    memberList.forEach(inviteTenderMember -> {
                        //投标会员
                        Long submitTenderMemberId = inviteTenderMember.getMemberId();
                        if (finalLoginMemberId.longValue() == submitTenderMemberId.longValue()) {
                            inviteTenderDoorWebResponse.setIsRegister(true);
                        }
                    });

                    //判断能否可以报名
                    inviteTenderDoorWebResponse.setCanRegister(finalMemberRoleType.intValue() == RoleTypeEnum.SERVICE_PROVIDER.getCode().intValue() && inviteTender.getMemberId().longValue() != finalLoginMemberId.longValue());
                }


                return inviteTenderDoorWebResponse;
            }).collect(Collectors.toList());
            return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
        } else {
            return Wrapper.success(new PageData<>(result.getTotalElements(), null));
        }
    }

    /**
     * 查询招标信息--采购招标详情
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getInviteTenderByWeb", method = RequestMethod.GET)
    public Wrapper<InviteTenderDetailWebResponse> getInviteTenderByWeb(@RequestParam Long inviteTenderId) {
        Long loginMemberId = null;
        Integer memberRoleType = null;
        //判断是否已登录
        if (this.isLogin()) {
            UserLoginCacheDTO sysUser = this.getSysUser();
            loginMemberId = sysUser.getMemberId();
            memberRoleType = sysUser.getMemberRoleType();
        }
        InviteTender inviteTender = inviteTenderService.getInviteTender(inviteTenderId);
        if (inviteTender != null) {
            InviteTenderDetailWebResponse inviteTenderDetailWebResponse = BeanUtil.copyProperties(inviteTender, InviteTenderDetailWebResponse.class);
            //计算报名剩余时间
            long nowTime = System.currentTimeMillis();
            long registerEndTime = inviteTenderDetailWebResponse.getRegisterEndTime();
            if (nowTime < registerEndTime) {
                long m = registerEndTime - nowTime;
                long days = m / 1000 / (60 * 60 * 24);
                inviteTenderDetailWebResponse.setDays(days);
                m = m - days * 1000 * (60 * 60 * 24);
                long hours = m / 1000 / (60 * 60);
                inviteTenderDetailWebResponse.setHours(hours);
                m = m - hours * 1000 * (60 * 60);
                long minutes = m / 1000 / 60;
                inviteTenderDetailWebResponse.setMinutes(minutes);
            }

            //判断是否登录
            if (loginMemberId != null) {
                //判断是否已经报名了
                List<InviteTenderMember> memberList = inviteTender.getMemberList();
                Long finalLoginMemberId = loginMemberId;
                memberList.forEach(inviteTenderMember -> {
                    //投标会员
                    Long submitTenderMemberId = inviteTenderMember.getMemberId();
                    if (finalLoginMemberId.longValue() == submitTenderMemberId.longValue()) {
                        inviteTenderDetailWebResponse.setIsRegister(true);
                    }
                });
                //判断能否可以报名
                inviteTenderDetailWebResponse.setCanRegister(RoleTypeEnum.SERVICE_PROVIDER.getCode().equals(memberRoleType) && !inviteTender.getMemberId().equals(finalLoginMemberId));
            }
            return Wrapper.success(inviteTenderDetailWebResponse);
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 查询流程步骤
     */
    @RequestMapping(value = "/getInviteTenderProcess", method = RequestMethod.GET)
    public Wrapper<ComplexTaskDefVO> getInviteTenderProcess(@RequestParam Long inviteTenderId) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.getInviteTenderProcess(sysUser, inviteTenderId));
    }

    /**
     * 招标--招标查询列表
     */
    @RequestMapping(value = "/getInviteTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getInviteTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            List<ExpertExtract> expertExtractList = inviteTender.getExpertExtractList();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            if (inviteTenderOutStatus.intValue() != InviteTenderOutStatusEnum.Discard_Tender.getCode().intValue()) {
                inviteTenderResponse.setIsDiscardTender(true);
            }
            if (inviteTenderOutStatus < InviteTenderOutStatusEnum.Not_Selection_Tender.getCode()) {
                inviteTenderResponse.setIsOpenTenderTime(true);
            }
            if (inviteTenderOutStatus >= InviteTenderOutStatusEnum.Not_Invite_Tender_Register.getCode() && inviteTenderOutStatus < InviteTenderOutStatusEnum.Not_Finish_Notice.getCode()) {
                if (expertExtractList == null || expertExtractList.size() == 0) {
                    inviteTenderResponse.setIsExpert(true);
                }
            }
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标-招标查询-外部状态
     */
    @RequestMapping(value = "/getInviteTenderOutStatus", method = RequestMethod.GET)
    public Wrapper<List<TenderStatusResponse>> getInviteTenderOutStatus() {
        InviteTenderOutStatusEnum[] values = InviteTenderOutStatusEnum.values();
        List<TenderStatusResponse> list = new ArrayList<>();
        for (InviteTenderOutStatusEnum inviteTenderOutStatusEnum : values) {
            Integer code = inviteTenderOutStatusEnum.getCode();
            String message = inviteTenderOutStatusEnum.getMessage();
            TenderStatusResponse tenderStatusResponse = new TenderStatusResponse();
            tenderStatusResponse.setCode(code);
            tenderStatusResponse.setMessage(message);
            list.add(tenderStatusResponse);
        }
        return Wrapper.success(list);
    }

    /**
     * 招标-招标查询-内部状态
     */
    @RequestMapping(value = "/getInviteTenderInStatus", method = RequestMethod.GET)
    public Wrapper<List<TenderStatusResponse>> getInviteTenderInStatus() {
        InviteTenderInStatusEnum[] values = InviteTenderInStatusEnum.values();
        List<TenderStatusResponse> list = new ArrayList<>();
        for (InviteTenderInStatusEnum inviteTenderInStatusEnum : values) {
            Integer code = inviteTenderInStatusEnum.getCode();
            String message = inviteTenderInStatusEnum.getMessage();
            TenderStatusResponse tenderStatusResponse = new TenderStatusResponse();
            tenderStatusResponse.setCode(code);
            tenderStatusResponse.setMessage(message);
            list.add(tenderStatusResponse);
        }
        return Wrapper.success(list);
    }

    /**
     * 招标--投标查询列表
     * @param submitTenderQueryRequest 分页实体
     */
    @RequestMapping(value = "/getSubmitTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getSubmitTenderList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        Page<InviteTenderMember> result = inviteTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
            Integer submitTenderInStatus = inviteTenderMember.getSubmitTenderInStatus();
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(submitTenderInStatus));
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标-投标查询-外部状态
     */
    @RequestMapping(value = "/getSubmitTenderOutStatus", method = RequestMethod.GET)
    public Wrapper<List<TenderStatusResponse>> getSubmitTenderOutStatus() {
        SubmitTenderOutStatusEnum[] values = SubmitTenderOutStatusEnum.values();
        List<TenderStatusResponse> list = new ArrayList<>();
        for (SubmitTenderOutStatusEnum submitTenderOutStatus : values) {
            Integer code = submitTenderOutStatus.getCode();
            if (code >= SubmitTenderOutStatusEnum.Not_Submit_Tender.getCode()) {
                String message = submitTenderOutStatus.getMessage();
                TenderStatusResponse tenderStatusResponse = new TenderStatusResponse();
                tenderStatusResponse.setCode(code);
                tenderStatusResponse.setMessage(message);
                list.add(tenderStatusResponse);
            }
        }
        return Wrapper.success(list);
    }

    /**
     * 招标--待新增招标列表
     */
    @RequestMapping(value = "/getAddInviteTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getAddInviteTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

       return inviteTenderService.getAddInviteTenderList(sysUser, inviteTenderQueryRequest,ShopTypeEnum.PURCHASE.getCode());

    }

    /**
     * 招标--待新增商城招标列表
     * @param inviteTenderQueryRequest 分页查询参数
     * @return 待新增招标分页列表
     */
    @RequestMapping(value = "/getShopAddInviteTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getShopAddInviteTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        return inviteTenderService.getAddInviteTenderList(sysUser,inviteTenderQueryRequest,ShopTypeEnum.ENTERPRISE.getCode());

    }

    /**
     * 招标--待审核招标(一级)列表
     */
    @RequestMapping(value = "/getCheckInviteTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getCheckInviteTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Tender_Check.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待审核招标(二级)列表
     */
    @RequestMapping(value = "/getCheckInviteTenderList2", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getCheckInviteTenderList2(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Tender_Check_2.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待提交招标列表
     */
    @RequestMapping(value = "/getCheckPassInviteTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getCheckPassInviteTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Submitted_Invite_Tender.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Tender_Check_Pass.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待审核报名列表
     * @param submitTenderQueryRequest 分页实体
     */
    @RequestMapping(value = "/getSubmitTenderCheckRegisterList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getSubmitTenderCheckRegisterList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Check_Register_Check.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);
        List<Integer> submitTenderInStatusList = new ArrayList<>();
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Submitted_Invite_Tender_Register.getCode());
        submitTenderQueryRequest.setSubmitTenderInStatusList(submitTenderInStatusList);

        Page<InviteTenderMember> result = inviteTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            //这里出现一对多的情况，内部状态显示跟外部状态一样
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待资格预审列表
     * @param submitTenderQueryRequest 分页实体
     */
    @RequestMapping(value = "/getSubmitTenderCheckQualificationsList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderMemberResponse>> getSubmitTenderCheckQualificationsList(@RequestBody SubmitTenderQueryRequest submitTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> submitTenderOutStatusList = new ArrayList<>();
        submitTenderOutStatusList.add(SubmitTenderOutStatusEnum.Not_Qualifications_Check.getCode());
        submitTenderQueryRequest.setSubmitTenderOutStatusList(submitTenderOutStatusList);
        List<Integer> submitTenderInStatusList = new ArrayList<>();
        submitTenderInStatusList.add(SubmitTenderInStatusEnum.Submitted_Qualifications_Check.getCode());
        submitTenderQueryRequest.setSubmitTenderInStatusList(submitTenderInStatusList);

        Page<InviteTenderMember> result = inviteTenderService.getSubmitTenderList(sysUser, submitTenderQueryRequest);
        List<InviteTenderMember> inviteTenderMemberList = result.getContent();
        List<InviteTenderMemberResponse> resultList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Integer submitTenderOutStatus = inviteTenderMember.getSubmitTenderOutStatus();
            InviteTenderMemberResponse inviteTenderMemberResponse = BeanUtil.copyProperties(inviteTenderMember, InviteTenderMemberResponse.class);
            //这里出现一对多的情况，内部状态显示跟外部状态一样
            inviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            inviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderOutStatusEnum.getMessage(submitTenderOutStatus));
            return inviteTenderMemberResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待提交评标报告列表
     */
    @RequestMapping(value = "/getEvaluationTenderReportList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getEvaluationTenderReportList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Not_Selection_Tender.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待定标列表
     */
    @RequestMapping(value = "/getFinishTenderReportList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getFinishTenderReportList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Not_Finish_Notice.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Submitted_Check_Finish_Tender.getCode());
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Finish_Tender_Check_Not_Pass.getCode());
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Finish_Tender_Check_Not_Pass_2.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待审核定标(一级)列表
     */
    @RequestMapping(value = "/getCheckFinishTenderReportList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getCheckFinishTenderReportList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Not_Finish_Notice.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Check_Finish_Tender.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待审核定标(二级)列表
     */
    @RequestMapping(value = "/getCheckFinishTenderReportList2", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getCheckFinishTenderReportList2(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Not_Finish_Notice.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Check_Finish_Tender_2.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待确认定标列表
     */
    @RequestMapping(value = "/getConfirmFinishTenderReportList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getConfirmFinishTenderReportList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Not_Finish_Notice.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Confirm_Finish_Tender.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--新增专家抽取--选择评标项目列表
     */
    @RequestMapping(value = "/getEvaluationTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getEvaluationTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        //查询所有小于评标截止时间且未组建评标委员会的招标项目数据，需求确认时间:2021-07-10 15:48:00
        inviteTenderQueryRequest.setLeEvaluationEndTime(true);
        inviteTenderQueryRequest.setIsNotExpertExtract(true);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 招标--待中标公示列表
     */
    @RequestMapping(value = "/getWinTenderList", method = RequestMethod.POST)
    public Wrapper<PageData<InviteTenderResponse>> getWinTenderList(@RequestBody InviteTenderQueryRequest inviteTenderQueryRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();

        List<Integer> inviteTenderOutStatusList = new ArrayList<>();
        inviteTenderOutStatusList.add(InviteTenderOutStatusEnum.Not_Win_Notice.getCode());
        inviteTenderQueryRequest.setInviteTenderOutStatusList(inviteTenderOutStatusList);
        List<Integer> inviteTenderInStatusList = new ArrayList<>();
        inviteTenderInStatusList.add(InviteTenderInStatusEnum.Not_Win_Notice.getCode());
        inviteTenderQueryRequest.setInviteTenderInStatusList(inviteTenderInStatusList);

        Page<InviteTender> result = inviteTenderService.getInviteTenderList(sysUser, inviteTenderQueryRequest);
        List<InviteTender> inviteTenderList = result.getContent();
        List<InviteTenderResponse> resultList = inviteTenderList.stream().map(inviteTender -> {
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();
            InviteTenderResponse inviteTenderResponse = BeanUtil.copyProperties(inviteTender, InviteTenderResponse.class);
            inviteTenderResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));
            inviteTenderResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            return inviteTenderResponse;
        }).collect(Collectors.toList());
        return Wrapper.success(new PageData<>(result.getTotalElements(), resultList));
    }

    /**
     * 查询招标信息
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getInviteTender", method = RequestMethod.GET)
    public Wrapper<InviteTenderDetailResponse> getInviteTender(@RequestParam Long inviteTenderId) {
        InviteTender inviteTender = inviteTenderService.getInviteTender(inviteTenderId);
        if (inviteTender != null) {
            InviteTenderDetailResponse inviteTenderDetailResponse = BeanUtil.copyProperties(inviteTender, InviteTenderDetailResponse.class);
            Integer inviteTenderOutStatus = inviteTender.getInviteTenderOutStatus();
            Integer inviteTenderInStatus = inviteTender.getInviteTenderInStatus();

            inviteTenderDetailResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTenderOutStatus));
            inviteTenderDetailResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTenderInStatus));

            //查询评标模板名称
            Long templateId = inviteTender.getTemplateId();
            if (templateId != null && templateId > 0) {
                Template template = templateService.getTemplate(templateId);
                if (template != null) {
                    inviteTenderDetailResponse.setTemplateName(template.getName());
                } else {
                    throw new BusinessException(ResponseCode.PURCHASE_TENDER_TEMPLATE_NOT_EXIST);
                }
            } else {
                throw new BusinessException(ResponseCode.PURCHASE_TENDER_TEMPLATE_NOT_EXIST);
            }

            //是否在线评标
            Boolean isOnlineEvaluation = inviteTender.getIsOnlineEvaluation();

            //评标记录（组装数据给前端）
            HashMap<Long, EvaluationInviteTenderMemberResponse> memberEvaluationTenderMap = new HashMap<>();
            List<EvaluationInviteTenderMemberResponse> evaluationInviteTenderMemberList = new ArrayList<>();
            List<InviteTenderMember> memberList = inviteTender.getMemberList();
            memberList.forEach(inviteTenderMember -> {
                //只查询已经投标的会员
                Boolean isSubmit = inviteTenderMember.getIsSubmit();
                if (isSubmit != null && isSubmit) {
                    EvaluationInviteTenderMemberResponse evaluationInviteTenderMember = new EvaluationInviteTenderMemberResponse();

                    Long memberId = inviteTenderMember.getMemberId();
                    String memberName = inviteTenderMember.getMemberName();
                    //非在线评标
                    if (!isOnlineEvaluation) {
                        List<EvaluationTenderOffline> evaluationTenderOfflineList = inviteTenderMember.getEvaluationTenderOfflineList();
                        List<EvaluationTenderDetailResponse> evaluationTenderList = evaluationTenderOfflineList.stream().map(evaluationTenderOffline -> {
                            Double score = evaluationTenderOffline.getScore();
                            TemplateContent templateContent = evaluationTenderOffline.getTemplateContent();
                            if (templateContent != null) {
                                EvaluationTenderDetailResponse evaluationTenderDetailResponse = new EvaluationTenderDetailResponse();
                                evaluationTenderDetailResponse.setScore(score);
                                evaluationTenderDetailResponse.setSort(templateContent.getSort());
                                evaluationTenderDetailResponse.setStandard(templateContent.getStandard());
                                evaluationTenderDetailResponse.setStandardScore(templateContent.getStandardScore());
                                evaluationTenderDetailResponse.setTerm(templateContent.getTerm());
                                return evaluationTenderDetailResponse;
                            } else {
                                return null;
                            }
                        }).filter(Objects::nonNull).collect(Collectors.toList());
                        evaluationInviteTenderMember.setEvaluationTenderList(evaluationTenderList);
                    }
                    evaluationInviteTenderMember.setId(memberId);
                    evaluationInviteTenderMember.setMemberId(memberId);
                    evaluationInviteTenderMember.setMemberName(memberName);
                    evaluationInviteTenderMember.setCorrectScore(inviteTenderMember.getCorrectScore());
                    memberEvaluationTenderMap.put(memberId, evaluationInviteTenderMember);
                    evaluationInviteTenderMemberList.add(evaluationInviteTenderMember);
                }
            });

            //在线评标
            if (isOnlineEvaluation) {
                List<ExpertExtract> expertExtractList = inviteTender.getExpertExtractList();
                expertExtractList.forEach(expertExtract -> {
                    List<ExpertExtractRecord> expertExtractRecordList = expertExtract.getExpertExtractRecordList();
                    expertExtractRecordList.forEach(expertExtractRecord -> {
                        List<EvaluationTenderOnline> evaluationTenderList = expertExtractRecord.getEvaluationTenderList();
                        evaluationTenderList.forEach(evaluationTender -> {
                            Long inviteTenderMemberId = evaluationTender.getInviteTenderMemberId();
                            EvaluationInviteTenderMemberResponse evaluationInviteTenderMember = memberEvaluationTenderMap.get(inviteTenderMemberId);
                            if (evaluationInviteTenderMember != null) {
                                EvaluationTenderDetailResponse evaluationTenderDetailResponse = BeanUtil.copyProperties(evaluationTender, EvaluationTenderDetailResponse.class);
                                SimpleIdRequest simpleIdRequest = new SimpleIdRequest();
                                simpleIdRequest.setId(expertExtractRecord.getId());
                                evaluationTenderDetailResponse.setExpertExtractRecord(simpleIdRequest);

                                List<EvaluationTenderDetailResponse> evaluationTenderDetailResponseList = evaluationInviteTenderMember.getEvaluationTenderList();
                                if (evaluationTenderDetailResponseList == null) {
                                    evaluationTenderDetailResponseList = new ArrayList<>();
                                }
                                if (!evaluationTenderDetailResponseList.contains(evaluationTenderDetailResponse)) {
                                    evaluationTenderDetailResponseList.add(evaluationTenderDetailResponse);
                                    evaluationInviteTenderMember.setEvaluationTenderList(evaluationTenderDetailResponseList);
                                }
                                memberEvaluationTenderMap.put(inviteTenderMemberId, evaluationInviteTenderMember);
                            }
                        });
                    });
                });

                //同一个专家对同一个会员的评分，按评分分类进行多个评分项的分数进行累加
                DecimalFormat decimalFormat = new DecimalFormat("#.00");
                evaluationInviteTenderMemberList.forEach(evaluationInviteTenderMemberResponse -> {
                    List<EvaluationTenderDetailResponse> evaluationTenderList = evaluationInviteTenderMemberResponse.getEvaluationTenderList();
                    if (evaluationTenderList != null && evaluationTenderList.size() > 0) {
                        List<Double> correctScoreList = new ArrayList<>();
                        List<EvaluationTenderDetailResponse> newEvaluationTenderList = new ArrayList<>();
                        // 通过combination返回的字符串分组，为key,相同的专家 + 评分分类为列表
                        Map<String, List<EvaluationTenderDetailResponse>> collect = evaluationTenderList.stream().collect(Collectors.groupingBy(this::combination, Collectors.toList()));
                        collect.forEach((key, list) -> {
                            double sum = list.stream().mapToDouble(EvaluationTenderDetailResponse::getScore).sum();
                            EvaluationTenderDetailResponse evaluationTenderDetailResponse = list.get(0);
                            evaluationTenderDetailResponse.setScore(Double.parseDouble(decimalFormat.format(sum)));
                            newEvaluationTenderList.add(evaluationTenderDetailResponse);

                            correctScoreList.add(sum);
                        });
                        evaluationInviteTenderMemberResponse.setEvaluationTenderList(newEvaluationTenderList);

                        //如果有修正总分，以修正总分为准，没有的话，按各项的评分累加
                        Double correctScore = evaluationInviteTenderMemberResponse.getCorrectScore();
                        if (correctScore == null) {
                            double sum = correctScoreList.stream().reduce(Double::sum).orElse(0D);
                            evaluationInviteTenderMemberResponse.setCorrectScore(Double.parseDouble(decimalFormat.format(sum)));
                        }
                    }
                });
            }
            inviteTenderDetailResponse.setEvaluationInviteMemberList(evaluationInviteTenderMemberList);

            return Wrapper.success(inviteTenderDetailResponse);
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 按专家 + 评分分类进行分组
     */
    private String combination(EvaluationTenderDetailResponse evaluationTenderDetailResponse) {
        return evaluationTenderDetailResponse.getExpertExtractRecord().getId() + evaluationTenderDetailResponse.getSort();
    }

    /**
     * 查询投标信息
     * @param submitTenderId 投标id
     */
    @RequestMapping(value = "/getSubmitTender", method = RequestMethod.GET)
    public Wrapper<SubmitTenderInviteTenderMemberDetailResponse> getSubmitTender(@RequestParam Long submitTenderId) {
        InviteTenderMember inviteTenderMember = inviteTenderService.getSubmitTenderMember(submitTenderId);
        if (inviteTenderMember != null) {
            SubmitTenderInviteTenderMemberDetailResponse inviteTenderMemberDetailResponse = BeanUtil.copyProperties(inviteTenderMember, SubmitTenderInviteTenderMemberDetailResponse.class);
            inviteTenderMemberDetailResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
            inviteTenderMemberDetailResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));

            //四舍五入，保留两位小数
            DecimalFormat decimalFormat = new DecimalFormat("#.00");
            //中标金额
            double winnerAmount = 0;
            double allWinnerAmount = 0;
            Boolean isWin = inviteTenderMember.getIsWin();
            if (isWin != null && isWin) {
                SubmitTender submitTender = inviteTenderMember.getSubmitTender();
                if (submitTender != null) {
                    List<SubmitTenderMateriel> submitTenderMaterielList = submitTender.getSubmitTenderMateriel();
                    if (submitTenderMaterielList != null && submitTenderMaterielList.size() > 0) {
                        for (SubmitTenderMateriel submitTenderMateriel : submitTenderMaterielList) {
                            Boolean isAwardTender = submitTenderMateriel.getIsAwardTender();
                            if (isAwardTender != null && isAwardTender) {
                                Double price = submitTenderMateriel.getPrice();
                                Double awardTenderRatio = submitTenderMateriel.getAwardTenderRatio();
                                Double count = submitTenderMateriel.getInviteTenderMateriel().getCount();
                                winnerAmount = winnerAmount + (price * awardTenderRatio * count / 100);
                                allWinnerAmount = allWinnerAmount + (price * count);
                            }
                        }
                    }
                }
            }

            inviteTenderMemberDetailResponse.setWinnerAmount(Double.parseDouble(decimalFormat.format(winnerAmount)));
            inviteTenderMemberDetailResponse.setAllWinnerAmount(Double.parseDouble(decimalFormat.format(allWinnerAmount)));

            return Wrapper.success(inviteTenderMemberDetailResponse);
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_SUBMIT_TENDER_NOT_EXIST);
        }
    }

    /**
     * 查询招标报名信息
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getInviteTenderRegister", method = RequestMethod.GET)
    public Wrapper<InviteTenderRegisterResponse> getInviteTenderRegister(@RequestParam Long inviteTenderId) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        InviteTender inviteTender = inviteTenderService.getInviteTender(inviteTenderId);
        if (inviteTender != null) {
            InviteTenderRegisterResponse inviteTenderRegisterResponse = BeanUtil.copyProperties(inviteTender, InviteTenderRegisterResponse.class);
            inviteTenderRegisterResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(SubmitTenderOutStatusEnum.Not_Invite_Tender_Register.getCode()));
            inviteTenderRegisterResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(SubmitTenderInStatusEnum.Not_Submitted_Invite_Tender_Register.getCode()));
            inviteTenderRegisterResponse.setSubmitTenderMemberId(sysUser.getMemberId());
            inviteTenderRegisterResponse.setSubmitTenderMemberName(sysUser.getCompany());
            return Wrapper.success(inviteTenderRegisterResponse);
        } else {
            throw new BusinessException(ResponseCode.PURCHASE_INVITE_TENDER_NOT_EXIST);
        }
    }

    /**
     * 新增/修改招标
     * @param inviteTenderAddRequest 招标实体
     * @return 招标id
     */
    @RequestMapping(value = "/saveOrUpdateInviteTender", method = RequestMethod.POST)
    public Wrapper<Long> saveOrUpdateInviteTender(@RequestBody InviteTenderAddRequest inviteTenderAddRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.saveOrUpdateInviteTender(sysUser, this.modelMapper.map(inviteTenderAddRequest, InviteTender.class)));
    }

    /**
     * 复制招标
     * @param simpleIdRequest 参数
     */
    @RequestMapping(value = "/copyInviteTender", method = RequestMethod.POST)
    public Wrapper<InviteTenderDetailResponse> copyInviteTender(HttpServletRequest request, @RequestBody SimpleIdRequest simpleIdRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser(request);
        InviteTender inviteTender = inviteTenderService.copyInviteTender(sysUser, simpleIdRequest.getId());
        return Wrapper.success(BeanUtil.copyProperties(inviteTender, InviteTenderDetailResponse.class));
    }

    /**
     * 修改开标时间
     * @param openTenderRequest 参数
     */
    @RequestMapping(value = "/updateOpenTender", method = RequestMethod.POST)
    public Wrapper<String> updateOpenTender(@RequestBody OpenTenderRequest openTenderRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.updateOpenTender(sysUser, openTenderRequest));
    }

    /**
     * 废标
     * @param discardRequest 参数
     */
    @RequestMapping(value = "/discardInviteTender", method = RequestMethod.POST)
    public Wrapper<String> discardInviteTender(@RequestBody DiscardRequest discardRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.discardInviteTender(sysUser, discardRequest));
    }

    /**
     * 批量提交审核
     * @param simpleIdListRequest 参数
     */
    @RequestMapping(value = "/applyCheckInviteTender", method = RequestMethod.POST)
    public Wrapper<String> applyCheckInviteTender(@RequestBody SimpleIdListRequest simpleIdListRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.applyCheckInviteTender(sysUser, simpleIdListRequest));
    }

    /**
     * 批量删除
     * @param simpleIdListRequest 招标
     */
    @RequestMapping(value = "/deleteInviteTender", method = RequestMethod.POST)
    public Wrapper<String> deleteInviteTender(@RequestBody SimpleIdListRequest simpleIdListRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.deleteInviteTender(sysUser, simpleIdListRequest));
    }

    /**
     * 审核招标
     * @param checkRequest 审核
     */
    @RequestMapping(value = "/checkInviteTender", method = RequestMethod.POST)
    public Wrapper<String> checkInviteTender(@RequestBody CheckRequest checkRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.checkInviteTender(sysUser, checkRequest));
    }

    /**
     * 审核招标(批量审核通过)
     * @param simpleIdListRequest 审核
     */
    @RequestMapping(value = "/checkInviteTenderBatch", method = RequestMethod.POST)
    public Wrapper<String> checkInviteTenderBatch(@RequestBody SimpleIdListRequest simpleIdListRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.checkInviteTenderBatch(sysUser, simpleIdListRequest));
    }

    /**
     * 提交招标
     * @param simpleIdListRequest 参数
     */
    @RequestMapping(value = "/submittedInviteTender", method = RequestMethod.POST)
    public Wrapper<String> submittedInviteTender(@RequestBody SimpleIdListRequest simpleIdListRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.submittedInviteTender(sysUser, simpleIdListRequest));
    }

    /**
     * 审核报名
     * @param checkRequest 审核
     */
    @RequestMapping(value = "/checkInviteTenderRegister", method = RequestMethod.POST)
    public Wrapper<String> checkInviteTenderRegister(@RequestBody CheckRequest checkRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.checkInviteTenderRegister(sysUser, checkRequest));
    }

    /**
     * 资格预审
     * @param checkRequest 审核
     */
    @RequestMapping(value = "/checkQualifications", method = RequestMethod.POST)
    public Wrapper<String> checkQualifications(@RequestBody CheckRequest checkRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.checkQualifications(sysUser, checkRequest));
    }

    /**
     * 查询审核定标
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getCheckFinishTender", method = RequestMethod.GET)
    public Wrapper<FinishInviteTenderDetailResponse> getCheckFinishTender(@RequestParam Long inviteTenderId) {
        InviteTender inviteTender = inviteTenderService.getInviteTender(inviteTenderId);
        FinishInviteTenderDetailResponse inviteTenderDetailResponse = BeanUtil.copyProperties(inviteTender, FinishInviteTenderDetailResponse.class);
        //状态转换
        inviteTenderDetailResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTender.getInviteTenderInStatus()));
        inviteTenderDetailResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTender.getInviteTenderOutStatus()));

        //区分是否在线评标
        Boolean isOnlineEvaluation = inviteTender.getIsOnlineEvaluation();
        if (isOnlineEvaluation) {
            getOnlineEvaluationInvite(inviteTenderDetailResponse, inviteTender.getMemberList(), inviteTender.getExpertExtractList());
        } else {
            getOfflineEvaluationInvite(inviteTenderDetailResponse, inviteTender.getMemberList());
        }
        return Wrapper.success(inviteTenderDetailResponse);
    }

    /**
     * 在线评标
     */
    private void getOnlineEvaluationInvite(FinishInviteTenderDetailResponse inviteTenderDetailResponse, List<InviteTenderMember> memberList, List<ExpertExtract> expertExtractList) {
        HashMap<Long, Double> memberCorrectScoreMap = new HashMap<>();
        List<EvaluationInviteTenderMemberResponse> evaluationInviteTenderMemberList = new ArrayList<>();

        List<FinishInviteTenderMemberResponse> finishInviteTenderMemberResponseList = inviteTenderDetailResponse.getMemberList();
        finishInviteTenderMemberResponseList.forEach(finishInviteTenderMemberResponse -> {
            Long finishInviteTenderId = finishInviteTenderMemberResponse.getId();
            memberList.forEach(inviteTenderMember -> {
                Long id = inviteTenderMember.getId();
                Long memberId = inviteTenderMember.getMemberId();
                //状态转换成中文
                if (finishInviteTenderId.longValue() == id.longValue()) {
                    finishInviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
                    finishInviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));

                    //会员修正总分
                    memberCorrectScoreMap.put(memberId, inviteTenderMember.getCorrectScore());
                }
            });
        });
        //定义临时变量
        List<ExpertExtractRecordDetailResponse> expertExtractRecordDetailList = new ArrayList<>();
        HashMap<Long, EvaluationInviteTenderMemberResponse> memberEvaluationTenderMap = new HashMap<>();

        expertExtractList.forEach(expertExtract -> {
            List<ExpertExtractRecord> expertExtractRecordList = expertExtract.getExpertExtractRecordList();
            expertExtractRecordList.forEach(expertExtractRecord -> {
                //投标会员（组装数据给前端）
                List<EvaluationTenderOnline> evaluationTenderList = expertExtractRecord.getEvaluationTenderList();
                evaluationTenderList.forEach(evaluationTender -> {
                    Long evaluationTenderId = evaluationTender.getId();
                    Long inviteTenderMemberId = evaluationTender.getInviteTenderMemberId();
                    String inviteTenderMemberName = evaluationTender.getInviteTenderMemberName();
                    EvaluationInviteTenderMemberResponse evaluationInviteTenderMember = memberEvaluationTenderMap.get(inviteTenderMemberId);
                    if (evaluationInviteTenderMember == null) {
                        evaluationInviteTenderMember = new EvaluationInviteTenderMemberResponse();
                        evaluationInviteTenderMember.setId(evaluationTenderId);
                        evaluationInviteTenderMember.setMemberId(inviteTenderMemberId);
                        evaluationInviteTenderMember.setMemberName(inviteTenderMemberName);
                        evaluationInviteTenderMember.setCorrectScore(memberCorrectScoreMap.get(inviteTenderMemberId));
                        evaluationInviteTenderMemberList.add(evaluationInviteTenderMember);
                    }

                    EvaluationTenderDetailResponse evaluationTenderDetailResponse = BeanUtil.copyProperties(evaluationTender, EvaluationTenderDetailResponse.class);
                    SimpleIdRequest simpleIdRequest = new SimpleIdRequest();
                    simpleIdRequest.setId(expertExtractRecord.getId());
                    evaluationTenderDetailResponse.setExpertExtractRecord(simpleIdRequest);

                    List<EvaluationTenderDetailResponse> evaluationTenderDetailResponseList = evaluationInviteTenderMember.getEvaluationTenderList();
                    if (evaluationTenderDetailResponseList == null) {
                        evaluationTenderDetailResponseList = new ArrayList<>();
                    }
                    if (!evaluationTenderDetailResponseList.contains(evaluationTenderDetailResponse)) {
                        evaluationTenderDetailResponseList.add(evaluationTenderDetailResponse);
                        evaluationInviteTenderMember.setEvaluationTenderList(evaluationTenderDetailResponseList);
                    }
                    memberEvaluationTenderMap.put(inviteTenderMemberId, evaluationInviteTenderMember);
                });
                //专家抽取记录
                ExpertExtractRecordDetailResponse expertExtractRecordDetail = BeanUtil.copyProperties(expertExtractRecord, ExpertExtractRecordDetailResponse.class);
                if (expertExtractRecordDetail != null && !expertExtractRecordDetailList.contains(expertExtractRecordDetail)) {
                    expertExtractRecordDetailList.add(expertExtractRecordDetail);
                }
            });
        });

        //同一个专家对同一个会员的评分，按评分分类进行多个评分项的分数进行累加
        DecimalFormat decimalFormat = new DecimalFormat("#.00");
        evaluationInviteTenderMemberList.forEach(evaluationInviteTenderMemberResponse -> {
            List<EvaluationTenderDetailResponse> evaluationTenderList = evaluationInviteTenderMemberResponse.getEvaluationTenderList();
            if (evaluationTenderList != null && evaluationTenderList.size() > 0) {
                List<Double> correctScoreList = new ArrayList<>();
                List<EvaluationTenderDetailResponse> newEvaluationTenderList = new ArrayList<>();
                // 通过combination返回的字符串分组，为key,相同的专家 + 评分分类为列表
                Map<String, List<EvaluationTenderDetailResponse>> collect = evaluationTenderList.stream().collect(Collectors.groupingBy(this::combination, Collectors.toList()));
                collect.forEach((key, list) -> {
                    double sum = list.stream().mapToDouble(EvaluationTenderDetailResponse::getScore).sum();
                    EvaluationTenderDetailResponse evaluationTenderDetailResponse = list.get(0);
                    evaluationTenderDetailResponse.setScore(Double.parseDouble(decimalFormat.format(sum)));
                    newEvaluationTenderList.add(evaluationTenderDetailResponse);

                    correctScoreList.add(sum);
                });
                evaluationInviteTenderMemberResponse.setEvaluationTenderList(newEvaluationTenderList);

                //如果有修正总分，以修正总分为准，没有的话，按各项的评分累加
                Double correctScore = evaluationInviteTenderMemberResponse.getCorrectScore();
                if (correctScore == null) {
                    double sum = correctScoreList.stream().reduce(Double::sum).orElse(0D);
                    evaluationInviteTenderMemberResponse.setCorrectScore(Double.parseDouble(decimalFormat.format(sum)));
                }
            }
        });

        inviteTenderDetailResponse.setExpertExtractList(expertExtractRecordDetailList);
        inviteTenderDetailResponse.setEvaluationInviteMemberList(evaluationInviteTenderMemberList);
    }

    /**
     * 非在线评标
     */
    private void getOfflineEvaluationInvite(FinishInviteTenderDetailResponse inviteTenderDetailResponse, List<InviteTenderMember> memberList) {
        List<FinishInviteTenderMemberResponse> finishInviteTenderMemberResponseList = inviteTenderDetailResponse.getMemberList();
        List<EvaluationInviteTenderMemberResponse> evaluationInviteTenderMemberList = new ArrayList<>();
        finishInviteTenderMemberResponseList.forEach(finishInviteTenderMemberResponse -> {
            Long finishInviteTenderMemberId = finishInviteTenderMemberResponse.getId();
            memberList.forEach(inviteTenderMember -> {
                Long id = inviteTenderMember.getId();
                Long memberId = inviteTenderMember.getMemberId();
                if (finishInviteTenderMemberId.longValue() == id.longValue()) {
                    finishInviteTenderMemberResponse.setSubmitTenderInStatusValue(SubmitTenderInStatusEnum.getMessage(inviteTenderMember.getSubmitTenderInStatus()));
                    finishInviteTenderMemberResponse.setSubmitTenderOutStatusValue(SubmitTenderOutStatusEnum.getMessage(inviteTenderMember.getSubmitTenderOutStatus()));

                    Boolean isSubmit = inviteTenderMember.getIsSubmit();
                    if (isSubmit) {
                        EvaluationInviteTenderMemberResponse evaluationInviteTenderMember = new EvaluationInviteTenderMemberResponse();
                        evaluationInviteTenderMember.setId(id);
                        evaluationInviteTenderMember.setMemberId(memberId);
                        evaluationInviteTenderMember.setMemberName(inviteTenderMember.getMemberName());
                        evaluationInviteTenderMember.setCorrectScore(inviteTenderMember.getCorrectScore());
                        List<EvaluationTenderOffline> evaluationTenderOfflineList = inviteTenderMember.getEvaluationTenderOfflineList();
                        List<EvaluationTenderDetailResponse> evaluationTenderList = evaluationTenderOfflineList.stream().map(evaluationTenderOffline -> {
                            Double score = evaluationTenderOffline.getScore();
                            TemplateContent templateContent = evaluationTenderOffline.getTemplateContent();
                            if (templateContent != null) {
                                EvaluationTenderDetailResponse evaluationTenderDetailResponse = new EvaluationTenderDetailResponse();
                                evaluationTenderDetailResponse.setScore(score);
                                evaluationTenderDetailResponse.setSort(templateContent.getSort());
                                evaluationTenderDetailResponse.setStandard(templateContent.getStandard());
                                evaluationTenderDetailResponse.setStandardScore(templateContent.getStandardScore());
                                evaluationTenderDetailResponse.setTerm(templateContent.getTerm());
                                return evaluationTenderDetailResponse;
                            } else {
                                return null;
                            }
                        }).filter(Objects::nonNull).collect(Collectors.toList());
                        evaluationInviteTenderMember.setEvaluationTenderList(evaluationTenderList);
                        evaluationInviteTenderMemberList.add(evaluationInviteTenderMember);
                    }
                }
            });
        });
        inviteTenderDetailResponse.setEvaluationInviteMemberList(evaluationInviteTenderMemberList);
    }

    /**
     * 提交审核定标
     * @param checkFinishTenderRequest 参数
     */
    @RequestMapping(value = "/submitCheckFinishTender", method = RequestMethod.POST)
    public Wrapper<String> submitCheckFinishTender(@RequestBody CheckFinishTenderRequest checkFinishTenderRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.submitCheckFinishTender(sysUser, checkFinishTenderRequest));
    }

    /**
     * 审核定标
     * @param checkRequest 审核
     */
    @RequestMapping(value = "/checkFinishTender", method = RequestMethod.POST)
    public Wrapper<String> checkFinishTender(@RequestBody CheckRequest checkRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.checkFinishTender(sysUser, checkRequest));
    }

    /**
     * 确认定标
     * @param simpleIdRequest 参数
     */
    @RequestMapping(value = "/finishTender", method = RequestMethod.POST)
    public Wrapper<String> finishTender(@RequestBody SimpleIdRequest simpleIdRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.finishTender(sysUser, simpleIdRequest));
    }

    /**
     * 查询中标公示
     * @param inviteTenderId 招标id
     */
    @RequestMapping(value = "/getWinTenderNotice", method = RequestMethod.GET)
    public Wrapper<WinTenderNoticeDetailResponse> getWinTenderNotice(@RequestParam Long inviteTenderId) {
        DecimalFormat decimalFormat = new DecimalFormat("#.00");
        InviteTender inviteTender = inviteTenderService.getInviteTender(inviteTenderId);
        WinTenderNoticeDetailResponse winTenderNoticeDetailResponse = BeanUtil.copyProperties(inviteTender, WinTenderNoticeDetailResponse.class);
        winTenderNoticeDetailResponse.setInviteTenderInStatusValue(InviteTenderInStatusEnum.getMessage(inviteTender.getInviteTenderInStatus()));
        winTenderNoticeDetailResponse.setInviteTenderOutStatusValue(InviteTenderOutStatusEnum.getMessage(inviteTender.getInviteTenderOutStatus()));
        //定义临时变量
        List<InviteTenderMember> inviteTenderMemberList = inviteTender.getMemberList();
        List<WinTenderMemberResponse> memberList = inviteTenderMemberList.stream().map(inviteTenderMember -> {
            Boolean isWin = inviteTenderMember.getIsWin();
            if (isWin != null && isWin) {
                double amount = 0d;
                WinTenderMemberResponse winTenderMemberResponse = new WinTenderMemberResponse();
                winTenderMemberResponse.setMemberId(inviteTenderMember.getMemberId());
                winTenderMemberResponse.setMemberName(inviteTenderMember.getMemberName());
                winTenderMemberResponse.setMemberRoleId(inviteTenderMember.getMemberRoleId());
                winTenderMemberResponse.setMemberRoleName(inviteTenderMember.getMemberRoleName());
                SubmitTender submitTender = inviteTenderMember.getSubmitTender();
                List<SubmitTenderMateriel> submitTenderMaterielList = submitTender.getSubmitTenderMateriel();
                if (submitTenderMaterielList != null && submitTenderMaterielList.size() > 0) {
                    for (SubmitTenderMateriel submitTenderMateriel : submitTenderMaterielList) {
                        //是否授标
                        Boolean isAwardTender = submitTenderMateriel.getIsAwardTender();
                        if (isAwardTender != null && isAwardTender) {
                            Double count = submitTenderMateriel.getInviteTenderMateriel().getCount();
                            Double price = submitTenderMateriel.getPrice();
                            Double awardTenderRatio = submitTenderMateriel.getAwardTenderRatio();
                            amount = amount + (count * price * awardTenderRatio / 100);
                        }
                    }
                }
                winTenderMemberResponse.setAmount(Double.parseDouble(decimalFormat.format(amount)));
                return winTenderMemberResponse;
            } else {
                return null;
            }
        }).filter(Objects::nonNull).collect(Collectors.toList());
        winTenderNoticeDetailResponse.setMemberList(memberList);
        return Wrapper.success(winTenderNoticeDetailResponse);
    }

    /**
     * 中标公示
     * @param winTenderRequest 参数
     */
    @RequestMapping(value = "/winTenderNotice", method = RequestMethod.POST)
    public Wrapper<String> winTenderNotice(@RequestBody WinTenderRequest winTenderRequest) {
        UserLoginCacheDTO sysUser = this.getSysUser();
        return Wrapper.success(inviteTenderService.winTenderNotice(sysUser, winTenderRequest));
    }

    /**
     * 更新招标对应的店铺积分
     */
    @RequestMapping(value = "/updateMemberCreditScore", method = RequestMethod.POST)
    public Wrapper<Boolean> updateMemberCreditScore(@RequestBody MemberCreditScore memberCreditScore) {
        return Wrapper.success(inviteTenderService.updateCommodityCreditScore(memberCreditScore));
    }
}
